<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="java.util.Date" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="com.lsl.endworkvol.entity.Activity" %>

<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <meta name="renderer" content="webkit">
    <title></title>
    <link rel="stylesheet" href="<%=request.getContextPath()%>/css/pintuer.css">
    <link rel="stylesheet" href="<%=request.getContextPath()%>/css/admin.css">
    <script src="<%=request.getContextPath()%>/js/jquery.js"></script>
    <script src="<%=request.getContextPath()%>/js/pintuer.js"></script>
</head>
<body>
<form method="post" action="search_activities" id="listform">
    <div class="panel admin-panel">
        <div class="panel-head"><strong class="icon-reorder">活动列表</strong> <a href="" style="float:right; display:none;">添加字段</a></div>
        <div class="padding border-bottom">
            <ul class="search" style="padding-left:10px;">
                <li>搜索：</li>
                <li>
                    <input type="text" placeholder="搜索：活动名" name="title" class="input" style="width:200px; line-height:17px;display:inline-block" />
                    <input type="text" placeholder="搜索：活动负责人" name="leader" class="input" style="width:200px; line-height:17px;display:inline-block" />
                    <input type="text" placeholder="搜索：活动地点" name="position" class="input" style="width:200px; line-height:17px;display:inline-block" />
                    <select name="acti_status" class="input" style="width:200px; line-height:17px;display:inline-block">
                        <option value="">搜索：活动状态</option>
                        <option value="未开始">未开始</option>
                        <option value="报名中">报名中</option>
                        <option value="报名已结束">报名已结束</option>
                        <option value="进行中">进行中</option>
                        <option value="已结束">已结束</option>
                    </select>
                    <a href="javascript:void(0)" class="button border-main icon-search" onclick="changeSearch()" > 搜索</a>
                </li>
            </ul>
        </div>
        <table class="table table-hover text-center">
            <tr>
                <th>活动ID</th>
                <th>活动名</th>
                <th>活动描述</th>
                <th>活动地点</th>
                <th>负责人</th>
                <th>报名开始时间</th>
                <th>报名结束时间</th>
                <th>活动开始时间</th>
                <th>活动结束时间</th>
                <th>状态</th>
                <th>人数</th>
                <th>操作</th>
            </tr>
           <c:forEach var="item" varStatus="looper" items="${activitiesList}" >
                <%
                    Activity item = (Activity) pageContext.getAttribute("item");
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                %>
                <tr>
                    <td>${item.id}</td>
                    <td>${item.title}</td>
                    <td>${item.caption}</td>
                    <td>${item.position}</td>
                    <td>${leadersNameList[looper.count-1]}</td>
                    <td><%=sdf.format(item.getSignUpStartTime())%></td>
                    <td><%=sdf.format(item.getSignUpEndTime())%></td>
                    <td><%=sdf.format(item.getStartTime())%></td>
                    <td><%=sdf.format(item.getEndTime())%></td>
                    <td>
                        <% 
                            Date now = new Date();
                            Date signUpStartTime = item.getSignUpStartTime();
                            Date signUpEndTime = item.getSignUpEndTime();
                            Date startTime = item.getStartTime();
                            Date endTime = item.getEndTime();
                            String status = "未知";
                            if (signUpStartTime != null && now.before(signUpStartTime)) {
                                status = "未开始";
                            } else if (endTime != null && now.after(endTime)) {
                                status = "已结束";
                            } else if (signUpStartTime != null && signUpEndTime != null && now.after(signUpStartTime) && now.before(signUpEndTime)) {
                                status = "报名中";
                            } else if (signUpEndTime != null && now.after(signUpEndTime) && startTime != null && now.before(startTime)) {
                                status = "报名已结束";
                            } else if (startTime != null && now.after(startTime) && endTime != null && now.before(endTime)) {
                                status = "进行中";
                            }
                        %>
                        <%=status%>
                    </td>
                    <td>${item.volunteerCount}/${item.volunteerMaxCount}</td>
                    <td>
                        <div class="button-group">
                            <a class="button border-main" href="activity_edit_page/${item.id}"><span class="icon-edit"></span> 修改</a>
                            <a class="button border-red" href="javascript:void(0)" onclick="deleteActivity('${item.id}')"><span class="icon-trash-o"></span> 删除</a>
                        </div>
                    </td>
                </tr>
            </c:forEach>
        </table>
        
        <!--分页-->
        <%-- <div class="pagelist">
         <a href="">上一页</a> <span class="current">1</span>
         <a href="">2</a><a href="">3</a><a href="">下一页</a><a href="">尾页</a> 
        </div> --%>
    </div>
</form>
<script type="text/javascript">
function changeSearch(){
    $("#listform").submit();
}

function deleteActivity(id){
    if(!confirm("您确定要删除该活动吗？")){
        return;
    }
    location.href = "delete_activity/"+id;
}
</script>
</body>
</html>
